package com.wdcloud.netlibrary.dispatcher;

import com.wdcloud.netlibrary.callback.DownloadFileCallback;
import com.wdcloud.netlibrary.callback.NetWorkCallback;
import com.wdcloud.netlibrary.util.OkHttpUtil;

import okhttp3.Request;

/**
 * Call的实现者，实现真正的网络请求调用
 * <p>
 */

public class CommonDispatcher implements IDispatcher {

    public Request request;

    private boolean isLocal = true;

    public CommonDispatcher(Request request) {
        this.request = request;
    }


    public <T> void enqueue(NetWorkCallback<T> callback) {
        OkHttpUtil.getInstance().enqueue(this, callback);
    }

    @Override
    public <T> T execute(Class<T> c) throws Exception {
        return OkHttpUtil.getInstance().execute(this, c);
    }

    @Override
    public <T> void execute(NetWorkCallback<T> callback) {
        OkHttpUtil.getInstance().execute(this, callback);
    }

    @Override
    public void downLoad(DownloadFileCallback callback) {
    }


    @Override
    public void downLoadWithMemory(DownloadFileCallback callback) {

    }

    @Override
    public IDispatcher backOnMain(boolean flag) {
        isLocal = !flag;
        return this;
    }

    @Override
    public boolean isLocal() {
        return isLocal;
    }
}
